import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";
import { sysCfgList } from "@/api/modules/system/params";

export const useUserStore = defineStore({
  id: "geeker-user",
  state: (): UserState => ({
    token: "",
    userInfo: { name: "" },
    licenseInfo: {
      isLicence: false,
      license: ""
    },
    appTitle: ""
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    setLicenseInfo(data) {
      this.licenseInfo = data;
    },
    async setAppTitle() {
      const res = await sysCfgList();
      this.appTitle = res.result.data.syslogo;
    }
  },
  persist: piniaPersistConfig("geeker-user")
});
